package com.gz.seckill.controller;

import com.gz.seckill.service.UserService;
import com.gz.seckill.vo.LoginVo;
import com.gz.seckill.vo.RespBean;
import com.sun.deploy.net.HttpResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

@Controller
@RequestMapping("/login")
@Slf4j
public class LoginController {

    @Autowired
    private UserService userService;

    //编写方法进入到登录页面
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }


    @ResponseBody
    @RequestMapping("/doLogin")
    public RespBean doLogin(@Valid LoginVo loginVo,
                            HttpServletRequest httpRequest,
                            HttpServletResponse httpResponse) {
        return userService.doLogin(loginVo,httpRequest,httpResponse);
    }
}
